"""
 encoding    : utf-8
 @File       : release_journal_test.py
 @Author     : sugar 
 @Version    :
 @Description:
 @Date       : 2024/06/15
"""
import pytest
from common.OA_tools import *
from selenium.webdriver.support.select import Select


@pytest.fixture
def my_fixture1():
    driver = webdriver.Firefox()
    global my_fixture
    my_fixture = Oa_Page(driver)
    my_fixture.open_llq()
    my_fixture.login()
    yield driver
    my_fixture.close_llq()


class TestReleaseAnnouncement:
    def test01_release(self, my_fixture1):
        self.driver = my_fixture1
        self.driver.find_element('link text', '公共信息').click()
        self.driver.find_element('xpath', '/html/body/div[2]/div/div[2]/table/tbody/tr[2]/td/a/img').click()
        f1 = self.driver.find_element('id', 'iframe_main')
        self.driver.switch_to.frame(f1)
        text = '发布公告测试标题1'
        self.driver.find_element('id', 'subject').send_keys(text)
        self.driver.find_element('id', 'trackInput').click()
        self.driver.find_element('xpath', '/html/body/div[3]/div[1]/button').click()
        f2 = self.driver.find_element('id', 'baidu_editor_0')
        self.driver.switch_to.frame(f2)
        self.driver.find_element('css selector', 'body').click()
        self.driver.find_element('css selector', 'body').send_keys('发布公告测试内容全体员工,行政公告')
        self.driver.switch_to.default_content()
        f3 = self.driver.find_element('id', 'iframe_main')
        self.driver.switch_to.frame(f3)
        self.driver.find_element('id', 'button_send').click()
        self.driver.switch_to.default_content()
        time.sleep(2)
        my_fixture.jietu(text)
        my_fixture.release_right()

    def test02_release(self, my_fixture1):
        '''部分员工'''
        self.driver = my_fixture1
        self.driver.find_element('link text', '公共信息').click()
        self.driver.find_element('xpath', '/html/body/div[2]/div/div[2]/table/tbody/tr[2]/td/a/img').click()
        f1 = self.driver.find_element('id', 'iframe_main')
        self.driver.switch_to.frame(f1)
        text = '发布公告测试标题2'
        self.driver.find_element('id', 'subject').send_keys(text)
        self.driver.find_element('id', 'trackInput').click()
        self.driver.find_element('xpath', '/html/body/div[3]/div[2]/button').click()
        self.driver.switch_to.default_content()
        f2 = self.driver.find_element('css selector', '.d-content > iframe:nth-child(1)')
        self.driver.switch_to.frame(f2)
        self.driver.find_element('id', 'DeptTreeDiv_4_span').click()
        self.driver.find_element('css selector', 'button.button:nth-child(8)').click()
        self.driver.find_element('css selector', 'button.Btnnormal:nth-child(1)').click()
        self.driver.switch_to.default_content()
        f3 = self.driver.find_element('id', 'iframe_main')
        self.driver.switch_to.frame(f3)
        ele = self.driver.find_element('id', 'categoryId')
        select_obj = Select(ele)
        select_obj.select_by_value('263')
        f4 = self.driver.find_element('id', 'baidu_editor_0')
        self.driver.switch_to.frame(f4)
        self.driver.find_element('css selector', 'body').click()
        self.driver.find_element('css selector', 'body').send_keys('发布公告测试内容2部分员工,其他公告')
        self.driver.switch_to.default_content()
        f5 = self.driver.find_element('id', 'iframe_main')
        self.driver.switch_to.frame(f5)
        self.driver.find_element('id', 'button_send').click()
        self.driver.switch_to.default_content()
        time.sleep(2)
        my_fixture.jietu(text)
        my_fixture.release_right()

    def test03_select(self, my_fixture1):
        '''查看公告功能测试'''
        self.driver = my_fixture1
        self.driver.find_element('link text', '公共信息').click()
        self.driver.find_element('xpath', '/html/body/div[2]/div/div[2]/table/tbody/tr[2]/td/a/img').click()
        f1 = self.driver.find_element('id', 'iframe_main')
        self.driver.switch_to.frame(f1)
        text = '发布公告测试标题3'
        self.driver.find_element('id', 'subject').send_keys(text)
        self.driver.find_element('id', 'trackInput').click()
        self.driver.find_element('xpath', '/html/body/div[3]/div[1]/button').click()
        f2 = self.driver.find_element('id', 'baidu_editor_0')
        self.driver.switch_to.frame(f2)
        self.driver.find_element('css selector', 'body').click()
        self.driver.find_element('css selector', 'body').send_keys('查看公告测试内容1')
        self.driver.switch_to.default_content()
        f3 = self.driver.find_element('id', 'iframe_main')
        self.driver.switch_to.frame(f3)
        self.driver.find_element('id', 'button_send').click()
        self.driver.switch_to.default_content()
        self.driver.find_element('css selector', '.d-button').click()
        self.driver.find_element('link text', '查看公告').click()
        f4 = self.driver.find_element('id', 'iframe_main')
        self.driver.switch_to.frame(f4)
        self.driver.find_element('xpath', '/html/body/form[1]/div[2]/div'
                                          '/div[1]/div[2]/table/tbody/tr[1]/td[2]/div/a').click()
        self.driver.switch_to.default_content()
        f5 = self.driver.find_element('css selector', '.d-content > iframe:nth-child(1)')
        self.driver.switch_to.frame(f5)
        my_fixture.jietu(text)
        ele = self.driver.find_element('id', 'contentDiv')
        assert ele.text == '查看公告测试内容1', '与预期结果不符合'
